<template>
  <div class="applyMarketReport-page" v-loading="loading">
    <h3>应用市场报表</h3>
    <AreaWarp :padding="true">
      <SearchWarp :label="'应用市场'">
        <el-input v-model.trim="searchInfo.marketName" placeholder="应用市场"></el-input>
      </SearchWarp>
      <BtnWarp>
        <el-button type="primary" icon="el-icon-search" @click="search">搜索</el-button>
        <el-button type="info" icon="el-icon-delete" @click="reset">重置</el-button>
      </BtnWarp>
    </AreaWarp>

    <!-- 查询结果 -->
    <AreaTitleWarp :title="'应用市场报表'">
      <el-button v-if="exportShow" type="primary" @click="exportData">导出</el-button>
    </AreaTitleWarp>
    <AreaWarp :padding="false">
      <el-table
        size="mini"
        :data="tableInfo.list"
        style="width: 100%"
        class="pub-table"
        header-row-class-name="pub-table-header-row"
        header-cell-class-name="pub-table-header-cell"
      >
        <el-table-column prop="marketName" label="应用市场" min-width="120"></el-table-column>
        <el-table-column prop="activeCount" label="app激活数" min-width="100"></el-table-column>
        <el-table-column label="注册数" min-width="120">
          <template slot-scope="scope">
            <span>{{scope.row.regCount == null ? 0 : scope.row.regCount}}</span>
          </template>
        </el-table-column>
        <el-table-column label="完成认证数" min-width="120">
          <template slot-scope="scope">
            <span>{{scope.row.authCount == null ? 0 : scope.row.authCount}}</span>
          </template>
        </el-table-column>
        <el-table-column label="申请人数" min-width="120">
          <template slot-scope="scope">
            <span>{{scope.row.applyCount == null ? 0 : scope.row.applyCount}}</span>
          </template>
        </el-table-column>
        <el-table-column label="放款人数" min-width="120">
          <template slot-scope="scope">
            <span>{{scope.row.payCount == null ? 0 : scope.row.payCount}}</span>
          </template>
        </el-table-column>
        <el-table-column label="注册-认证转换率" min-width="120">
           <template slot-scope="scope">
            <span>{{accMul(scope.row.regAuthCount,100)}}%</span>
          </template>
        </el-table-column>
        <el-table-column label="注册-申请转换率" min-width="120">
           <template slot-scope="scope">
            <span>{{accMul(scope.row.regApplyCount,100)}}%</span>
          </template>
        </el-table-column>
        <el-table-column  label="注册-放款转换率" min-width="120">
           <template slot-scope="scope">
            <span>{{accMul(scope.row.regPayCount,100)}}%</span>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        layout="total,sizes,prev, pager, next, jumper"
        class="pub-page"
        :current-page="tableInfo.page"
        :page-size="tableInfo.size"
        :total="tableInfo.total"
        @current-change="search"
        @size-change="handleSizeChange"
        :page-sizes="[20, 50, 100]"
      ></el-pagination>
    </AreaWarp>
  </div>
</template>
<script>
import Data from "../../../assets/js/data.js";
export default {
  data() {
    return {
      searchInfo: {
        marketName: "",
        page: 1,
        size: 20
      },
      loading: false,
      tableInfo: {
        list: [],
        total: 0
      },
      exportShow: false
    };
  },
  methods: {
    handleSizeChange(val) {
      let that = this;
      that.searchInfo.size = val;
      that.searchInfo.page = 1;
      that.search();
    },
    search(currentPage) {
      let that = this;
      that.searchInfo.page = typeof currentPage == "number" ? currentPage : 1;
      let x = {
        marketName: that.searchInfo.marketName,
        page: that.searchInfo.page,
        size: that.searchInfo.size
      };
      let data = new Data(x);
      let reqData = data.getState();
      if (reqData.code) {
        that.showMsg(reqData.message, "error");
        return;
      }
      that.loading = true;
      that.ajaxJson({
        url: "/market/report/market/v2",
        data: reqData,
        success: function(res) {
          if (res.code == "0") {
            that.tableInfo = res.data;
          }
          that.loading = false;
        }
      });
    },
    reset() {
      let that = this;
      that.searchInfo = {
        marketName: "",
        page: 1,
        size: 20
      };
      that.search();
    },
    exportData() {
      let that = this;
      that.searchInfo.page = typeof currentPage == "number" ? currentPage : 1;
      let x = {
        marketName: that.searchInfo.marketName,
        page: that.searchInfo.page,
        size: that.searchInfo.size
      };
      let data = new Data(x);
      let reqData = data.getState();

      let url =
        that.host + "/market/export/v2?appId=" + that.$store.state.id;
      if (reqData.startTime) {
        url += "&startTime=" + reqData.startTime;
      }
      if (reqData.endTime) {
        url += "&endTime=" + reqData.endTime;
      }
      window.open(url);
    },
    isExportShow() {
      let that = this;
      let isExportShow = that
        .urlPermissions()
        .indexOf("/market/export/v2");
      if (isExportShow == "-1") {
        that.exportShow = false;
      } else {
        that.exportShow = true;
      }
    }
  },
  created() {
    let that = this;
    Promise.all([that.isExportShow()]).then(arr => {
      that.search();
    });
  }
};
</script>
<style lang="less">
.applyMarketReport-page {
}
</style>
